<template>
    <a-form layout="inline">
        <a-row :gutter="24">
            <a-col :md="8" :sm="24">
                <a-form-item label="统计范围">
                    <a-range-picker v-model="params.createTime"/>
                </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
                <span class="table-page-search-submitButtons">
                    <a-button type="primary" @click="query" :loading="loading">查询</a-button>
                </span>
            </a-col>
        </a-row>
    </a-form>
</template>

<script>
    export default {
        name: "StatisticsFilter",
        props: {
            loading: {
                type: Boolean,
                default: false
            }
        },
        data() {
            return {
                params: {}
            }
        },
        methods: {
            query() {
                this.parseTime('createTime')
                this.$emit('query', this.params)
            },
            parseTime(key) {
                let legal = this.params[key] && this.params[key].length === 2
                this.params[key + 'Begin'] = legal && this.params[key][0].valueOf() || null
                this.params[key + 'End'] = legal && this.params[key][1].valueOf() || null
            }
        }
    }
</script>
